<template>
  <page-header-wrapper :title="false">
    <a-card title="商品详情">
      <a-descriptions bordered title="" size="small">
        <a-descriptions-item label="商品名" :span="3"> {{ detail.goodsName }} </a-descriptions-item>
        <a-descriptions-item label="品牌" :span="3">{{ detail.brandName }}</a-descriptions-item>
        <a-descriptions-item label="一级分类" :span="3"> {{ detail.className1 }} </a-descriptions-item>
        <a-descriptions-item label="二级分类" :span="3"> {{ detail.className2 }} </a-descriptions-item>
        <a-descriptions-item label="串码" :span="3"> {{ detail.phoneCode1 }} </a-descriptions-item>
        <a-descriptions-item label="串码2" :span="3"> {{ detail.phoneCode2 }} </a-descriptions-item>
        <a-descriptions-item label="状态" :span="3"> 
          <template>
            <a-tag color="#82af6f" v-if="detail?.status == 0">退库</a-tag>
            <a-tag color="#82af6f" v-if="detail?.status == 1">在库</a-tag>
            <a-tag color="#82af6f" v-if="detail?.status == 2">返厂中</a-tag>
            <a-tag color="#82af6f" v-if="detail?.status == 3">调库中</a-tag>
            <a-tag color="#82af6f" v-if="detail?.status == 4">报损</a-tag>
            <a-tag color="#82af6f" v-if="detail?.status == 5">批发出库</a-tag>
            <a-tag color="#82af6f" v-if="detail?.status == 6">售出</a-tag>
          </template>
        </a-descriptions-item>
        <a-descriptions-item label="最近位置" :span="3"> {{ detail.gpsAddress }} </a-descriptions-item>
        <a-descriptions-item label="供应商" :span="3"> {{ detail.supplyName }} </a-descriptions-item>
        <a-descriptions-item label="渠道" :span="3"> {{ detail.channelName }} </a-descriptions-item>
        <a-descriptions-item label="入库日期" :span="3">{{ detail.inDate }} </a-descriptions-item>
        <a-descriptions-item label="成本" :span="3">  <a @click="handleChangeRecord(detail)">变更记录</a> </a-descriptions-item>
        <a-descriptions-item label="考核成本" :span="3"> {{ detail.assCost }} </a-descriptions-item>
        <a-descriptions-item label="零售价" :span="3"> {{ detail.price }} </a-descriptions-item>
        <a-descriptions-item label="固定提成" :span="3"> {{ detail.fixWage }} </a-descriptions-item>
      </a-descriptions>

    </a-card>
    <a-card title="流转记录" style="margin-top: 24px;">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="8">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.keyword" placeholder="请输入"/>
              </a-form-item>
            </a-col>
            <a-col :md="!advanced && 8 || 24" :sm="24">
              <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 
      <div class="table-operator">
        <a-button icon="cloud-upload">导出</a-button>
      </div> -->

      <a-table 
        ref="table" 
        size="default" 
        rowKey="key" 
        :columns="columns"
        :data-source="loadData"
        :pagination="pagination"
        @change="handleTableChange">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            {{ record.operType }} <a-tag color="#428bca">详情</a-tag>
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getInventoryByIdUsingGET, } from '@/api/api/kucunguanli.ts'
import { getInvRecordListUsingGET, } from '@/api/api/caigouguanli.ts'
export default {
  name: 'GoodsNameDetail',
  components:{
  },
  data() {
    return {
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        queryCondition: '',
        status: '',
        orderId:this.$route.params.id
      },
      advanced: false,
      priceMdll: null,
      editMdll: null,
      priceVisible: false,
      editVisible: false,
      priceLoading: false,
      editLoading: false,
      loading:false,
      pagination:{},
      columns: [
        {
          title: '流转时间',
          dataIndex: 'operTime',
        },
        {
          title: '流转详情',
          dataIndex: 'action',
          width: '150px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      loadData: [],
      detail: {},
    }
  },
  mounted() {
    this.getDetail()
    this.handleSearch(this.queryParam)
  },
  methods: {
    getDetail() {
      getInventoryByIdUsingGET({ id: this.$route.params.id })
        .then((res) => {
          this.detail = res.data
        })
        .catch(() => {
          this.$message.error('获取详情失败,请联系管理员')
        })
    },
    handleSearch (params) {
      this.loading = true
      getInvRecordListUsingGET(params)
        .then((res) => {
          this.loadData = res.data.list
          this.loading = false
          this.queryParam.pageNo = this.pagination.current
          this.pagination = { ...this.pagination, total: Number(res.data.total) }
        })
        .catch((error) => {
          this.loading = false
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
 pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.handleSearch({
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
        pageNo: pagination.current,
        pageSize: pagination.pageSize,
        orderId:this.$route.params.id,
        queryCondition:this.queryParam.queryCondition,
        status:this.queryParam.status,
        date:this.queryParam.date
      })
    },
    handleChangeRecord(detail) {
      this.$router.push({ path: `/goods/name/change/${detail.id}` })
    }
  },
}
</script>
